﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SUMO.MediaBrowser.Foundation;
using System.Windows.Media.Imaging;
using USTF.Media.MediaService;

namespace SUMO.MediaBrowser
{
    public class UmbracoMediaItem
    {
        protected ImageSource _sourceImage;

        public MediaItem MediaCarrier
        {
            get;
            set;

        }


        public ImageSource SourceImage
        {
            get
            {
                if (_sourceImage == null)
                {
                    OpsContext.DebugWrite(this.Uri);
                    OpsContext.DebugWrite(new Uri(this.Uri, UriKind.Absolute).AbsoluteUri);
                    _sourceImage = new BitmapImage(new Uri(this.Uri, UriKind.Absolute));

                    return _sourceImage;
                }
                else
                {
                    return _sourceImage;
                }
            }
            set
            {
                _sourceImage = value;
            }
        }

        public string Uri
        {
            get
            {
                return "DONT!";
                //Uri u = new Uri(OpsContext.Current.ServiceBase);
                //string baseUrl = u.Scheme + "://" + u.Host + ":" + u.Port;

                //string uri = "";
                //if (this.MediaCarrier.MediaProperties != null)
                //{
                //    foreach (mediaProperty p in this.MediaCarrier.MediaProperties)
                //    {
                //        if (p.Key.ToLower().Equals("umbracofile"))
                //        {
                //            uri = (string)p.PropertyValue;
                //        }
                //    }
                //}
                //if (uri.Length > 0)
                //{
                //    return baseUrl + uri;
                //}
                //else
                //{
                //    return "";
                //}
            }
        }

        public UmbracoMediaItem(MediaItem m)
        {
            this.MediaCarrier = m;
        }
    }
}
